package authoritah.utils;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtils {

	private static SimpleDateFormat dateFormat;
	
	static {
		dateFormat = new SimpleDateFormat("HH:mm");
	}
	
	public static Timestamp parseTime(Date date, String timeString) {
		try {
			Date newDate = dateFormat.parse(timeString);
			date.setHours(newDate.getHours());
			date.setMinutes(newDate.getMinutes());
			return new Timestamp(date.getTime());
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static Timestamp parseTime(String timeString) {
		try {
			Date date = dateFormat.parse(timeString);
			return new Timestamp(date.getTime());
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static String getTimeFromTimestamp(Timestamp timestamp) {
		return dateFormat.format(timestamp);
	}
	
	public static int calculatePoints(Timestamp start, Timestamp end) {
		long startTimestamp = start.getTime();
		long endTimestamp = end.getTime();
		long difference = endTimestamp - startTimestamp;
		
		return (int)difference / 3600000;
	}
}
